package com.example.test02sqlcompile.service;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.example.test02sqlcompile.common.BaseMapper;
import com.example.test02sqlcompile.domain.Entity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

/**
 * @Author: fxy
 * @Date: 2021/09/09/17:37
 * @Description:
 */
public abstract class BaseService<M extends BaseMapper,T extends Entity> {
    @Autowired
    protected M baseMapper;

    @Autowired
    public M getBaseMapper() {
        return this.baseMapper;
    }

    public int create(T entity){
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorker.get32UUID());
        }

        return this.baseMapper.insert(entity);
    }
}
